<!-- 成绩分布 -->
<template>
  <div>
    <el-dialog
      title="成绩分布"
      v-model="visible"
      width="50%"
      top="2%"
      @close="onClose"
    >
      <template #title>
        <p class="dialog-title">成绩分布</p>
      </template>
      <body>
        <header>
          <div>
            <p>100</p>
            <p>已批改人数</p>
          </div>
          <div>
            <p>98</p>
            <p>最高分</p>
          </div>
          <div>
            <p>100</p>
            <p>最低分</p>
          </div>
          <div>
            <p>80</p>
            <p>平均分</p>
          </div>
        </header>
        <aside>
          <div>
            <h1>Top10</h1>
            <div v-for="(item, index) in preList" :key="index">
              <div>
                <div class="preName">
                  <el-avatar
                    style="width: 0.2rem; height: 0.2rem; cursor: pointer"
                    :src="item.imgSrc"
                  />
                  <p>{{ item.name }}</p>
                </div>
                <div class="preScore">{{ item.score }}</div>
                <div>No.{{ index + 1 }}</div>
              </div>
            </div>
          </div>
        </aside>
        <footer>
          <bar-graph :width="'4.8rem'" :height="'1.6rem'" :barTitle="'成绩分布'"></bar-graph>
        </footer>
      </body>
      <!-- <template #footer>
        <span class="dialog-footer">
          <el-button size="mini" @click="onClose">取 消</el-button>
          <el-button size="mini" type="primary">确 定</el-button>
        </span>
      </template> -->
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { defineComponent, toRefs, reactive, watch } from "vue";
import genNickName from "@/views/data/radomName";
import barGraph from "@/views/components/echarts/barGraph.vue";
interface Props {
  dialogVisible: boolean;
}
interface State {
  visible: boolean;
}
export default defineComponent({
  name: "Dialog",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  components: {
    barGraph,
  },
  setup(props, context) {
    const { dialogVisible } = toRefs(props as Props);
    const parent = { ...context };
    const state = reactive<State>({
      visible: dialogVisible.value,
    });
    watch(
      dialogVisible,
      (newValue) => {
        state.visible = newValue;
      },
      { immediate: true }
    );
    const onClose = () => {
      parent.emit("update:dialogVisible", false);
    };
    /**
     * 前十名数组参数
     */
    const preList = reactive([
      {
        name: genNickName(),
        score: 100,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 99,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 98,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 97,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 96,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 95,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 94,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 93,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 92,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
      {
        name: genNickName(),
        score: 91,
        imgSrc:
          "https://video.kts.g.mi.com/ktv_1095733246_NUhIVHZRVkl3bGlESHh3Nml4b01zQT09_1650626656602.jpg",
      },
    ]);
    return {
      ...toRefs(state),
      onClose,
      preList,
    };
  },
});
</script>
<style lang="scss" scoped>
.dialog-title {
  font-size: 0.1rem;
  font-weight: bold;
  text-align: center;
}
body {
  header {
    display: flex;
    justify-content: space-between;
    div {
      width: 21%;
      margin: 0 2%;
      border: 0.01rem solid rgb(187, 187, 187);
      padding: 0.1rem 0;
      p {
        text-align: center;
        font-size: 0.09rem;
        font-weight: bold;
        line-height: 0.12rem;
        color: #000;
      }
    }
  }
}
aside {
  margin-top: 0.1rem;
  margin-bottom: 0.1rem;
  > div {
    padding-left: 4%;
    h1 {
      font-weight: bold;
      font-size: 0.1rem;
      line-height: 0.2rem;
      color: #000;
    }
    > div {
      display: inline-block;
      width: 50%;
      margin-bottom: 0.08rem;
      > div {
        display: flex;
        line-height: 0.2rem;
        color: #000;
        font-size: 0.08rem;
        .preName {
          display: flex;
          width: 40%;
          p {
            margin-left: 0.06rem;
          }
        }
        .preScore {
          width: 30%;
        }
      }
    }
  }
}
</style>
